package com.crm.web.interceptor;

import org.apache.struts2.ServletActionContext;

import com.crm.domain.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

/**
 * @author Yusei
 * 权限拦截器
 */

public class PrivilegeInterceptor extends MethodFilterInterceptor {

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		// 判断session中是否有用户登录信息
		User existUser = (User)ServletActionContext.getRequest().getSession().getAttribute("existUser");
		// 判断是否为空
		if (existUser == null) {
			// 返回错误信息
			ActionSupport actionSupport = (ActionSupport)invocation.getAction();
			actionSupport.addActionError("请登录后再进行操作");
			return actionSupport.LOGIN;
			// return "login";
		}else{
			// 放行,通知struts2接着做下面的事情
			return invocation.invoke();
		}
	}

}
